import re


class Cache():
    def __init__(self):
        self.data = {}

    def __call__(self, *args):
        if len(args) == 3:
            name, key, value = args

            if not name in self.data:
                self.data[name] = {}

            self.data[name][key] = value

        elif len(args) == 2:
            key, value = args

            self.data[key] = value

    def get(self, *args):
        if len(args) == 2:
            name, key = args

            if not name in self.data or not key in self.data[name]:
                return

            return self.data[name][key]
        elif len(args) == 1:
            key = args[0]

            if key in self.data:
                return self.data[key]

    def clear(self, *args):
        if len(args) == 0:
            self.data = {}

        elif len(args) == 2:
            name, key = args

            if not name in self.data or not key in self.data[name]:
                return

            del self.data[name][key]

        elif len(args) == 1:
            key = args[0]

            del self.data[key]


class Prov_City():
    def __init__(self):
        self.data = {}

        with open('prov_city.txt', 'r', encoding = 'utf-8') as f:
            prov = ""

            for line in f.readlines():
                if len(line.strip()) == 0:
                    continue

                if line.find('*') != -1:
                    prov = line.strip()[1:]
                    self.data[prov] = []
                    continue

                self.data[prov].append(line.strip().split()[0])
                self.data[prov].append(line.strip().split()[0].replace('市', ''))

    def parse(self, info):
        result = []

        for p in re.split('[+ ]', info):
            if p not in self.data:
                result.append(p)
            else:
                result += self.data[p]

        return result
